package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbIncome;
import com.ruoyi.system.service.ITbIncomeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * Controller
 * 
 * @author ruoyi
 * @date 2022-03-19
 */
@RestController
@RequestMapping("/system/income")
public class TbIncomeController extends BaseController
{
    @Autowired
    private ITbIncomeService tbIncomeService;

    @GetMapping("/list")
    public TableDataInfo list(TbIncome tbIncome)
    {
        startPage();
        List<TbIncome> list = tbIncomeService.selectTbIncomeList(tbIncome);
        return getDataTable(list);
    }


    @PostMapping("/export")
    public void export(HttpServletResponse response, TbIncome tbIncome)
    {
        List<TbIncome> list = tbIncomeService.selectTbIncomeList(tbIncome);
        ExcelUtil<TbIncome> util = new ExcelUtil<TbIncome>(TbIncome.class);
        util.exportExcel(response, list, "数据");
    }


    @GetMapping(value = "/{incomeId}")
    public AjaxResult getInfo(@PathVariable("incomeId") Long incomeId)
    {
        return AjaxResult.success(tbIncomeService.selectTbIncomeByIncomeId(incomeId));
    }


    @PostMapping
    public AjaxResult add(@RequestBody TbIncome tbIncome)
    {
        return toAjax(tbIncomeService.insertTbIncome(tbIncome));
    }


    @PutMapping
    public AjaxResult edit(@RequestBody TbIncome tbIncome)
    {
        return toAjax(tbIncomeService.updateTbIncome(tbIncome));
    }

	@DeleteMapping("/{incomeIds}")
    public AjaxResult remove(@PathVariable Long[] incomeIds)
    {
        return toAjax(tbIncomeService.deleteTbIncomeByIncomeIds(incomeIds));
    }
}
